package cn.cupk.corporateshuttlemanagesystem.mapper;

import cn.cupk.corporateshuttlemanagesystem.pojo.Routes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CompanyReservationInformationMapper {


    @Select({
            "<script>",
            "SELECT * FROM routes",
            "<where>",
            "<if test='name != null'>",
            "AND name LIKE CONCAT('%', #{name}, '%')",
            "</if>",
            "<if test='companyId != null'>",
            "AND company_id = #{companyId}",
            "</if>",
            "</where>",
            "</script>"
    })
    List<Routes> page(Routes routes);


    @Select({
            "<script>",
            "SELECT name FROM stops",
            "WHERE stop_id IN",
            "<foreach collection='routeId' item='item' index='index' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    List<String> stopList(List<Integer> routeId);

    @Select("SELECT user_id FROM routes WHERE route_id = #{routeId}")
    String selectOne(Integer routeId);

    @Update("UPDATE routes set user_id = #{userId} WHERE route_id=#{routeId}")
    Integer order(Integer routeId,String userId); //更新用户信息

    @Select("SELECT * FROM routes WHERE route_id = #{routeId}")
    Routes selectByRouteId(Integer routeId);

    @Update("UPDATE routes set user_id = #{s} WHERE route_id=#{routeId}")
    Integer updateOrder(String s,Integer routeId);


}
